﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Drawing;
using System.Drawing.Imaging;
using MapCenterSystem.Utility;
using MapCenterSystem.DefineType;

namespace MapCenterSystem.DataInfo
{
    public class MapInfoEx: MapInfo
    {
        public int MapSource; //0: Google, 1: Local
        public int MapType;
        public Coordinate CoordinateCenter;
        public Point MapCenter;

        public string GetFullPath()
        {
            string name = string.Empty;
            if(MapSource == 0)
                name=string.Format("{0}_{1}_{2}_{3}.png", MapType, Zoom, Tile.X, Tile.Y);
            else
                name = string.Format("{0}_{1}_{2}.png", Zoom, Tile.X, Tile.Y);
            string path = Path.Combine(MapStore, name);
            return path;
        }

        public bool CheckExist()
        {
            return File.Exists(GetFullPath());
        }

        public byte[] ConvertToByte()
        {
            Bitmap map = new Bitmap(GetFullPath());
            MemoryStream ms = new MemoryStream();
            map.Save(ms, ImageFormat.Png);
            byte[] byteResult = ms.ToArray();
            ms.Close();
            map.Dispose();
            return byteResult;
        }

        public void GlobalToMap()
        {
            MapCenter = LocateConvert.ToPoint(CoordinateCenter, Zoom);
        }
    }
}
